/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Aplicacion.java
 *
 * Created on 02-06-2011, 03:33:38 PM
 */

package aplicacion;


import acercade.AcercaDe;
import acercade.GPL;
import clases.*;
import java.awt.Color;
import java.net.URL;
import java.net.URLConnection;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author F
 */
public class Aplicacion extends javax.swing.JFrame {

    /** Creates new form Aplicacion */
    private boolean exArchivoDeConf;
    private ArchivoDeConfiguracion ar;

    public Aplicacion() {
        initComponents();
        llave1.setValue(3);
        llave2.setValue(3);
        Cifrado.setLlave(3);
        Redimensionar.redimensionarFormulario(this, false, "Cifrado Cesar");
        Cambiar.cambiarIcono(this, "/iconos/cifrado.png");
        principal.setVisible(false);
        contraseña.setVisible(true);
        if(!Archivo.existeArchivo("configuracion"+P.SEPARADOR+"config.cfg")){
            exArchivoDeConf = false;
//            ar = new ArchivoNoExistente("configuracion"+P.SEPARADOR, "config", "cfg");
            Mensajes.mensajeInformacion("Cree una Contraseña Nueva");
            btnOlvide.setEnabled(false);
            btnCambiar.setEnabled(false);
        }else{
            pMail.setVisible(false);
            exArchivoDeConf = true;
            ar = new ArchivoExistente("configuracion"+P.SEPARADOR+"config.cfg");
        }
//        Cifrado.setLlave(34);
//        System.out.println(Cifrado.decifrar("glph xqd iudvh x rudflrq"));
        so.setText(P.SO);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        formMail = new javax.swing.JFrame();
        jPanel1 = new javax.swing.JPanel();
        mail = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        btnAceptar = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        codRecu = new javax.swing.JTextField();
        jButton12 = new javax.swing.JButton();
        clave = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel9 = new javax.swing.JLabel();
        estIcon = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        formCambiarContraseña = new javax.swing.JFrame();
        jPanel2 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        conNue2 = new javax.swing.JPasswordField();
        conAnt = new javax.swing.JPasswordField();
        conNue1 = new javax.swing.JPasswordField();
        jButton9 = new javax.swing.JButton();
        principal = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        textoOriginal = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        textoCifrado = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblLlave = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        llave1 = new javax.swing.JSpinner();
        jButton4 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        llave2 = new javax.swing.JSpinner();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jButton8 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        so = new javax.swing.JLabel();
        contraseña = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        pass = new javax.swing.JPasswordField();
        jButton7 = new javax.swing.JButton();
        btnOlvide = new javax.swing.JButton();
        pMail = new javax.swing.JPanel();
        email = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        btnCambiar = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        formMail.getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Recuperar Clave"));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        mail.setEnabled(false);
        jPanel1.add(mail, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 40, 200, -1));

        jLabel10.setText("Mail:");
        jPanel1.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 40, -1, 20));

        jLabel11.setForeground(new java.awt.Color(1, 1, 1));
        jLabel11.setText("no deseados.");
        jPanel1.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 130, -1, -1));

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });
        jPanel1.add(btnAceptar, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 130, 120, -1));

        jLabel13.setForeground(new java.awt.Color(1, 1, 1));
        jLabel13.setText("Nota:   Se enviará un correo electrónico ");
        jPanel1.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 70, -1, -1));

        jLabel12.setText("Código de Recuperación:");
        jPanel1.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 190, -1, 20));
        jPanel1.add(codRecu, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 190, 140, -1));

        jButton12.setText("Recuperar Clave");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton12, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 220, 140, -1));

        clave.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        clave.setForeground(new java.awt.Color(255, 0, 0));
        clave.setText("clave");
        jPanel1.add(clave, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 250, 250, -1));

        jLabel15.setForeground(new java.awt.Color(255, 0, 0));
        jLabel15.setText("Su Clave:");
        jPanel1.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 250, 50, -1));
        jPanel1.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 170, 330, 10));

        jLabel9.setText("Internet:");
        jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 10, -1, -1));

        estIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/offline.gif"))); // NOI18N
        estIcon.setText("Desconectado");
        jPanel1.add(estIcon, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 10, 100, -1));

        jLabel20.setForeground(new java.awt.Color(1, 1, 1));
        jLabel20.setText("con un código de  recuperación de Clave.");
        jPanel1.add(jLabel20, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 90, -1, -1));

        jLabel21.setForeground(new java.awt.Color(1, 1, 1));
        jLabel21.setText("Si su correo es Hotmail, revise los correos");
        jPanel1.add(jLabel21, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 110, -1, -1));

        formMail.getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 340, 270));

        formCambiarContraseña.getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Cambiar Contraseña"));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel17.setText("Repita Nueva Contraseña:");
        jPanel2.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 90, -1, 20));

        jLabel18.setText("Contraseña Actual:");
        jPanel2.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 30, -1, 20));

        jLabel19.setText("Nueva Contraseña: ");
        jPanel2.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 60, -1, 20));
        jPanel2.add(conNue2, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 90, 120, -1));
        jPanel2.add(conAnt, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 30, 120, -1));
        jPanel2.add(conNue1, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 60, 120, -1));

        formCambiarContraseña.getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 400, 130));

        jButton9.setText("Cambiar Contraseña");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });
        formCambiarContraseña.getContentPane().add(jButton9, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 130, -1, -1));

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        principal.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jSplitPane1.setDividerLocation(397);

        textoOriginal.setColumns(20);
        textoOriginal.setRows(5);
        textoOriginal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                textoOriginalKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(textoOriginal);

        jSplitPane1.setLeftComponent(jScrollPane1);

        textoCifrado.setColumns(20);
        textoCifrado.setRows(5);
        textoCifrado.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                textoCifradoKeyReleased(evt);
            }
        });
        jScrollPane2.setViewportView(textoCifrado);

        jSplitPane1.setRightComponent(jScrollPane2);

        principal.add(jSplitPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 60, 800, 340));

        jButton1.setText("Guardar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        principal.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 400, 80, -1));

        jButton2.setText("Abrir");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        principal.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 400, 80, -1));

        jButton3.setText("Guardar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        principal.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 400, 80, -1));

        jButton5.setText("Abrir");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        principal.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 400, 80, -1));

        jLabel1.setText("Texto Cifrado:");
        principal.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 40, -1, 20));

        jLabel2.setText("Texto Original:");
        principal.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, -1, 20));

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel4.setText("S.O. Actual:");
        principal.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 10, -1, 20));

        lblLlave.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lblLlave.setText("3");
        principal.add(lblLlave, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 10, 230, -1));

        jLabel3.setText("Llave: ");
        principal.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 400, -1, 20));
        principal.add(llave1, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 400, 50, -1));

        jButton4.setText("Cambiar LLave");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        principal.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 400, 120, -1));

        jButton6.setText("Cambiar LLave");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        principal.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 400, 120, -1));
        principal.add(llave2, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 400, 50, -1));

        jLabel5.setText("Llave: ");
        principal.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, 400, -1, 20));

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/llave.png"))); // NOI18N
        principal.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, 20));

        jButton8.setText("Bloquear");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        principal.add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 0, 110, -1));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel8.setText("Llave Actual:");
        principal.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 10, -1, -1));

        so.setText("xx");
        principal.add(so, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 10, 160, 20));

        getContentPane().add(principal, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 800, 430));

        contraseña.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel7.setText("Contraseña:");
        contraseña.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 290, -1, 20));

        pass.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                passKeyPressed(evt);
            }
        });
        contraseña.add(pass, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 290, 90, -1));

        jButton7.setText("Iniciar Aplicación");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        contraseña.add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 320, 160, -1));

        btnOlvide.setText("Olvidé mi Contraseña");
        btnOlvide.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOlvideActionPerformed(evt);
            }
        });
        contraseña.add(btnOlvide, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 390, 160, -1));

        pMail.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        pMail.add(email, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 10, 190, -1));

        jLabel14.setText("E-Mail:");
        pMail.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, -1, 20));

        contraseña.add(pMail, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 250, 290, 30));

        btnCambiar.setText("Cambiar Contraseña");
        btnCambiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCambiarActionPerformed(evt);
            }
        });
        contraseña.add(btnCambiar, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 350, 160, -1));

        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/cifrado.png"))); // NOI18N
        contraseña.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 20, 240, 250));

        getContentPane().add(contraseña, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 7, 400, -1));

        jMenu1.setText("Ayuda");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        jMenuItem1.setText("Acerca de Cifrado Cesar");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void textoOriginalKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textoOriginalKeyReleased
        textoCifrado.setText(Cifrado.cifrar(textoOriginal.getText()));
    }//GEN-LAST:event_textoOriginalKeyReleased

    private void textoCifradoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textoCifradoKeyReleased
        textoOriginal.setText(Cifrado.decifrar(textoCifrado.getText()));
    }//GEN-LAST:event_textoCifradoKeyReleased

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        if(Integer.parseInt(llave1.getValue().toString()) > 0 && Integer.parseInt(llave1.getValue().toString()) <= 150){
            Cifrado.setLlave(llave1.getValue());
            lblLlave.setText(Long.toString(Cifrado.getLlave()));
            textoOriginalKeyReleased(null);
            llave2.setValue(Cifrado.getLlave());
        }else if(Integer.parseInt(llave1.getValue().toString()) < 0){
            llave1.setValue(3);
            llave2.setValue(3);
            jButton4ActionPerformed(null);
        }else{
            llave1.setValue(150);
            llave2.setValue(150);
            jButton4ActionPerformed(null);
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        Abrir a = new Abrir();
        if(a.abrir("cif", "Abrir Texto Original", P.SEPARADOR)){
            textoOriginal.setText(Archivo.leerArchivo(a.getRuta()));
            textoOriginalKeyReleased(null);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        Abrir a = new Abrir();
        if(a.abrir("cif", "Abrir Texto Cifrado", P.SEPARADOR)){
            textoCifrado.setText(Archivo.leerArchivo(a.getRuta()));
            textoCifradoKeyReleased(null);
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        Guardar g = new Guardar();
        if(g.guardarComo("Texto Original", "cif", "Guardar Texto Original", P.SEPARADOR)){
            Archivo.escribirEnAchivo(g.getRuta(), textoOriginal.getText(), true, false);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Guardar g = new Guardar();
        if(g.guardarComo("Texto Cifrado", "cif", "Guardar Texto Cifrado", P.SEPARADOR)){
            Archivo.escribirEnAchivo(g.getRuta(), textoCifrado.getText(), true, false);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
       if(Integer.parseInt(llave2.getValue().toString()) > 0 && Integer.parseInt(llave2.getValue().toString()) <= 150){
            Cifrado.setLlave(llave2.getValue());
            lblLlave.setText(Long.toString(Cifrado.getLlave()));
            textoCifradoKeyReleased(null);
            llave1.setValue(Cifrado.getLlave());
        }else if(Integer.parseInt(llave2.getValue().toString()) < 0){
            llave1.setValue(3);
            llave2.setValue(3);
        }else{
            llave1.setValue(150);
            llave2.setValue(150);
            jButton6ActionPerformed(null);
        }
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        validar();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void passKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_passKeyPressed
        if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER){
            validar();
        }
    }//GEN-LAST:event_passKeyPressed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        principal.setVisible(false);
        pass.setText("");
        contraseña.setVisible(true);
        btnOlvide.setEnabled(true);
        btnCambiar.setEnabled(true);
        pass.requestFocus();
    }//GEN-LAST:event_jButton8ActionPerformed

    private void btnOlvideActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOlvideActionPerformed
        Redimensionar.redimensionarFormulario(formMail, false, "Recuperar Contraseña");
        Cambiar.cambiarIcono(formMail, "/iconos/llave.png");
        formMail.setVisible(true);
        clave.setVisible(false);
        Cambiar.cambiarIconoLabel(estIcon,(Conectividad.isConectado()?"/iconos/online.gif":"/iconos/offline.gif") );
        estIcon.setText(Conectividad.isConectado()?"Conectado":"Desconectado");
        btnAceptar.setEnabled(Conectividad.isConectado()?true:false);
        decifrarArchivoDeConfiguracion();
        mail.setText(ar.getValorDeConfiguracion("mail"));
        cifrarArchivoDeConfiguracion();
        codRecu.setText("");
        clave.setText("");
    }//GEN-LAST:event_btnOlvideActionPerformed

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        String codRan = CodigoRandom.getCodigo(12);
        this.decifrarArchivoDeConfiguracion();
        ar.actualizarCampo("recuperar", codRan);
        this.cifrarArchivoDeConfiguracion();
        Mail.setMailEmisor("noreplay.cifrado@gmail.com", "07091988", "No Replay Cifrado Cesar");
        Mail.setAsunto("Recuperación Clave");
        Mail.setMensaje("Código de Recuperación: "+codRan);
//        System.out.println(mail.getText()+(dominio.getSelectedIndex() != 3 ?dominio.getSelectedItem().toString():""));
        Mail.enviarMail(mail.getText());
//        if(){
//            Mensajes.mensajeInformacion("E-Mail enviado exitósamente");
//        }else{
//            Mensajes.mensajeError("Error al enviar el Correo");
//        }
    }//GEN-LAST:event_btnAceptarActionPerformed

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
        this.decifrarArchivoDeConfiguracion();
        String c1 = ar.getValorDeConfiguracion("recuperar");
        if(codRecu.getText().equalsIgnoreCase(c1)){
            clave.setVisible(true);
            clave.setText(ar.getValorDeConfiguracion("clave"));
            this.cifrarArchivoDeConfiguracion();
        }else{
            this.cifrarArchivoDeConfiguracion();
            System.out.println("Recu Archivo ="+c1);
            Mensajes.mensajeError("Código de Recuperación Erróneo");
        }

    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        String c1, c2, c3;
        c1 = conAnt.getText();
        c2 = conNue1.getText();
        c3 = conNue2.getText();

        decifrarArchivoDeConfiguracion();
        String contActual = ar.getValorDeConfiguracion("clave");
        cifrarArchivoDeConfiguracion();

        if(c1.equalsIgnoreCase(contActual)){
            if(c2.equalsIgnoreCase(c3)){
                decifrarArchivoDeConfiguracion();
                ar.actualizarCampo("clave", c2);
                cifrarArchivoDeConfiguracion();
                Mensajes.mensajeInformacion("Contraseña Cambiada Exitosamente");
                formCambiarContraseña.setVisible(false);
            }else{
                Mensajes.mensajeError("Las contrasenas Nuevas no coinciden");
                conNue1.setText("");
                conNue2.setText("");
                conNue1.requestFocus();
            }
        }else{
            Mensajes.mensajeError("La contraseña actual no coincide con la ingresada");
            conAnt.setText("");
            conAnt.requestFocus();
        }
    }//GEN-LAST:event_jButton9ActionPerformed

    private void btnCambiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCambiarActionPerformed
        conAnt.setText("");
        conNue1.setText("");
        conNue2.setText("");
        conAnt.requestFocus();
        Cambiar.cambiarIcono(formCambiarContraseña, "/iconos/llave.png");
        Redimensionar.redimensionarFormulario(formCambiarContraseña, false, "Cambio de Contraseña");
        formCambiarContraseña.setVisible(true);
    }//GEN-LAST:event_btnCambiarActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    AcercaDe a = new AcercaDe("Cifrado Cesar", "Un programa Simple para cifrar texto", "Patricio Pérez Pinto","2011", "patricio.perez.pinto@gmail.com", GPL.AMBAS_VERSIONES);
    a.setVisible(true);
}//GEN-LAST:event_jMenuItem1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            java.awt.EventQueue.invokeLater(new Runnable() {

                public void run() {
                    new Aplicacion().setVisible(true);
                }
            });
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCambiar;
    private javax.swing.JButton btnOlvide;
    private javax.swing.JLabel clave;
    private javax.swing.JTextField codRecu;
    private javax.swing.JPasswordField conAnt;
    private javax.swing.JPasswordField conNue1;
    private javax.swing.JPasswordField conNue2;
    private javax.swing.JPanel contraseña;
    private javax.swing.JTextField email;
    private javax.swing.JLabel estIcon;
    private javax.swing.JFrame formCambiarContraseña;
    private javax.swing.JFrame formMail;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JLabel lblLlave;
    private javax.swing.JSpinner llave1;
    private javax.swing.JSpinner llave2;
    private javax.swing.JTextField mail;
    private javax.swing.JPanel pMail;
    private javax.swing.JPasswordField pass;
    private javax.swing.JPanel principal;
    private javax.swing.JLabel so;
    private javax.swing.JTextArea textoCifrado;
    private javax.swing.JTextArea textoOriginal;
    // End of variables declaration//GEN-END:variables

    private void cifrarArchivoDeConfiguracion() {
        long llave = Cifrado.getLlave();
        String nombreAr = "configuracion"+P.SEPARADOR+"config.cfg";
        Cifrado.setLlave(3);
        Archivo.escribirEnAchivo(nombreAr, Cifrado.cifrar(Archivo.leerArchivo(nombreAr)), true, false);
        Cifrado.setLlave(llave);
    }

    private void decifrarArchivoDeConfiguracion() {
        long llave = Cifrado.getLlave();
        String nombreAr = "configuracion"+P.SEPARADOR+"config.cfg";
        Cifrado.setLlave(3);
        Archivo.escribirEnAchivo(nombreAr, Cifrado.decifrar(Archivo.leerArchivo(nombreAr)), true, false);
        Cifrado.setLlave(llave);
    }

    private void validar() {
        if(!exArchivoDeConf){
            if(!email.getText().trim().equalsIgnoreCase("")){
                ar = new ArchivoNoExistente("configuracion"+P.SEPARADOR, "config", "cfg");
                pMail.setVisible(false);
                decifrarArchivoDeConfiguracion();
                ar.setCampoDeConfiguracion("mail", email.getText());
                ar.setCampoDeConfiguracion("clave", pass.getText());
                ar.setCampoDeConfiguracion("recuperar", CodigoRandom.getCodigo(6));
                contraseña.setVisible(false);
                principal.setVisible(true);
                cifrarArchivoDeConfiguracion();
                exArchivoDeConf = true;
            }else{
                Mensajes.mensajeError("Debe Ingresar un Email");
                email.requestFocus();
            }
        }else{
            String passwd = pass.getText();
            decifrarArchivoDeConfiguracion();
            if(passwd.equalsIgnoreCase(ar.getValorDeConfiguracion("clave"))){
                contraseña.setVisible(false);
                principal.setVisible(true);
            }else{
                Mensajes.mensajeError("Contraseña Errónea");
                pass.setText("");
                pass.requestFocus();
            }
            cifrarArchivoDeConfiguracion();
        }
    }

    

}
